﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Zhongy
{
    public delegate void ExecuteDelegate();
    public class SingleExecute
    {
        private static SingleExecute instance = null;

        public static SingleExecute Instance
        {
            get
            {
                lock (o)
                {
                    if(instance == null)
                        instance = new SingleExecute();
                    return instance;
                }
            }
        }

        private static object o = 99;

        public Mutex mutex;

        private SingleExecute()
        {
            mutex = new Mutex();
        }

        public void Execute(ExecuteDelegate exexuteDelegate)
        {
            lock (this)
            {
                mutex.WaitOne();
                exexuteDelegate();
                mutex.ReleaseMutex();
            }
        }
    }
}
